package com.miraeasset.toxml;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;


public class TestXmlGen {
	private IXmlGenerator gen;
	private List<Map<Object, Object>> insertedMap;
	private String xmlheader = "<?xml version='1.0' encoding='utf-8'?>";

	private Map<Object,Object> getTestMap(){
		Map<Object,Object> map = new HashMap<Object, Object>();
		map.put("name", "kangjin");
		map.put("age", "29");
		return map;
	}
	
	@Before
	public void setUp() throws Exception {
		insertedMap = new Vector<Map<Object,Object>>();
		for(int i=0; i < 2; i++)
			insertedMap.add(getTestMap());
		gen = XMLGeneratorFactory.getInstance(TypeOfXmlGenerator.LIST_CONSISTOF_MAP);
		gen.setData(insertedMap);
	}
	@Test
	public void test_toXml()
	{
		String result = xmlheader + "<AGE>29</AGE><NAME>kangjin</NAME><AGE>29</AGE><NAME>kangjin</NAME>";
		Assert.assertEquals(result, gen.toXml());
	}

	@Test
	public void test_toXml_with_sectionTag()
	{
		gen.setSectionTag("gubun");
		String result = xmlheader + "<GUBUN><AGE>29</AGE><NAME>kangjin</NAME></GUBUN><GUBUN><AGE>29</AGE><NAME>kangjin</NAME></GUBUN>";
		Assert.assertEquals(result, gen.toXml());
	}

	@Test
	public void test_toXml_with_parentTag()
	{
		gen.setSectionTag("gubun");
		gen.setParentTag("test");
		String result = xmlheader + "<TEST><GUBUN><AGE>29</AGE><NAME>kangjin</NAME></GUBUN><GUBUN><AGE>29</AGE><NAME>kangjin</NAME></GUBUN></TEST>";
		Assert.assertEquals(result, gen.toXml());
	}

}
